class Solution {
public:
    vector<int> getSumAbsoluteDifferences(vector<int>& nums) {
        int n=nums.size();
        int sum=0;
        for(auto m:nums){
            sum+=m;
        }
        int presum=0;
        for(int i=0;i<n;i++){
            presum+=nums[i];
            nums[i]=(nums[i]*(i+1)-presum)+(sum-presum-(n-i-1)*nums[i]);
        }
        return nums;
    }
};